from odoo import fields, models, api, _
from odoo.exceptions import ValidationError


class WorkflowCheckWizard(models.TransientModel):
    _inherit = "workflow.check.wizard"

    def approval_pass(self):
        """审批通过, 请购单情况下, 一级审批请购价格必须完善才通过"""
        self = self.sudo()
        if self.workflow_type == 'purchase_requisition':
            sb_workflow_item_id = self.sb_workflow_item_id.sb_workflow_id.sb_workflow_item_ids[0]
            if sb_workflow_item_id == self.sb_workflow_item_id:
                requisition_id = self.sb_workflow_item_id.sb_workflow_id.purchase_requisition_id
                for rec in requisition_id.pr_line_ids:
                    if rec.unit_price <= 0:
                        pass
                        # raise ValidationError(_(f'Please first complete: {rec.product_id.name} Requisition price!'))
        return super(WorkflowCheckWizard, self).approval_pass()
